{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  刘入铭\n",
    "+ 学号  0151819"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该农户不是贫困户\n",
      "\n",
      "\n",
      "此农户为贫困户\n",
      "住房扶贫已完成\n",
      "饮水扶贫已完成\n",
      "食物扶贫已完成\n",
      "\n",
      "\n",
      "此农户为贫困户\n",
      "教育扶贫已完成\n",
      "饮水扶贫已完成\n",
      "食物扶贫已完成\n"
     ]
    }
   ],
   "source": [
    "class Poor(object):\n",
    "    \n",
    "    def __init__(self, x1=0, x2=0, x3=0, x4=0):\n",
    "        self.education = x1\n",
    "        self.housing = x2\n",
    "        self.drinking = x3\n",
    "        self.protein = x4\n",
    "        \n",
    "    def judgement(self):\n",
    "        sum = self.education + self.housing + self.drinking + self.protein\n",
    "        if sum <= 1:\n",
    "            print(\"此农户为贫困户\")\n",
    "        else:\n",
    "            print(\"该农户不是贫困户\")\n",
    "            \n",
    "    def improve_education(self, improve=False):\n",
    "        if improve == True:\n",
    "            self.education = 1\n",
    "            print(\"教育扶贫已完成\")\n",
    "    \n",
    "    def improve_housing(self, improve=False):\n",
    "        if improve == True:\n",
    "            self.housing = 1\n",
    "            print(\"住房扶贫已完成\")\n",
    "\n",
    "    def improve_drinking(self, improve=False):\n",
    "        if improve == True:\n",
    "            self.drinking = 1\n",
    "            print(\"饮水扶贫已完成\")\n",
    "                  \n",
    "    def improve_protein(self, improve=False):\n",
    "        if improve == True:\n",
    "            self.protein = 1\n",
    "            print(\"食物扶贫已完成\")\n",
    "    \n",
    "farmer1 = Poor(1,1,1,1)\n",
    "farmer1.judgement()\n",
    "print(\"\\n\")\n",
    "\n",
    "farmer2 = Poor(1,0,0,0)\n",
    "farmer2.judgement()\n",
    "farmer2.improve_housing(True)\n",
    "farmer2.improve_drinking(True)\n",
    "farmer2.improve_protein(True)\n",
    "print(\"\\n\")\n",
    "\n",
    "farmer3 = Poor(0,0,0,1)\n",
    "farmer3.judgement()\n",
    "farmer3.improve_education(improve=True)\n",
    "farmer3.improve_drinking(improve=True)\n",
    "farmer3.improve_protein(improve=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "刘入铭体重正常。\n",
      "KobeBMI可能偏大。\n",
      "RonBMI可能偏大。\n"
     ]
    }
   ],
   "source": [
    "class Info(object):\n",
    "    def __init__(self, name, score, sleep):\n",
    "        self.name = name\n",
    "        self.score = score\n",
    "        self.sleep = sleep\n",
    "        \n",
    "    def obesity(self, mark=90, time=6):\n",
    "        if self.score > mark and self.sleep < time:\n",
    "            print(self.name + \"BMI可能偏大。\")\n",
    "        else:\n",
    "            print(self.name + \"体重正常。\")\n",
    "            \n",
    "    \n",
    "            \n",
    "stu1 = Info('刘入铭', 100, 10)\n",
    "stu1.obesity()\n",
    "\n",
    "stu2 = Info('Kobe', 85, 7)\n",
    "stu2.obesity(mark=80, time=8)\n",
    "\n",
    "stu3 = Info('Ron', 80, 8)\n",
    "stu3.obesity(70, 9)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "刘入铭体重趋向正常\n",
      "gjy体重正常\n",
      "Kobe体重正常\n"
     ]
    }
   ],
   "source": [
    "class Info(object):\n",
    "    def __init__(self, name, score, sleep):\n",
    "        self.name = name\n",
    "        self.score = score\n",
    "        self.sleep = sleep\n",
    "        \n",
    "    def obesity(self, mark=90, time=6):\n",
    "        if self.score > mark and self.sleep < time:\n",
    "            print(self.name + \"BMI可能偏大。\")\n",
    "        else:\n",
    "            print(self.name + \"体重正常。\")\n",
    "            \n",
    "class Run(Info):\n",
    "    def __init__(self, name, score, sleep, run):\n",
    "        super().__init__(name, score, sleep)\n",
    "        self.run = run\n",
    "        \n",
    "    def judement(self, mark=90, time=6):\n",
    "        if self.score > mark and self.sleep <time:\n",
    "            if self.run > 30:\n",
    "                print(self.name + \"体重趋向正常\")\n",
    "            else:\n",
    "                print(self.name + \"BMI可能偏大\")\n",
    "        else:\n",
    "            print(self.name + \"体重正常\")\n",
    "            \n",
    "stu1 = Run(\"刘入铭\", 100, 5, 40)\n",
    "stu1.judement()\n",
    "\n",
    "stu2 = Run(\"gjy\", 100, 8, 20)\n",
    "stu2.judement()\n",
    "\n",
    "stu3 = Run(\"Kobe\", 90, 5, 20)\n",
    "stu3.judement()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
